package juc.day02;


import java.util.concurrent.TimeUnit;

/**
 * 8锁问题
 */
public class Lock8 {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        Phone phone2 = new Phone();
        new Thread(()->{
            try {
                phone2.sendSMS();
            }catch (Exception e){
                e.printStackTrace();
            }
        },"AA").start();

        Thread.sleep(100);

        new Thread(()->{
            try {
                phone.sendEmail();
            }catch (Exception e){
                e.printStackTrace();
            }
        },"BB").start();
    }
}

class Phone{
    public static synchronized void sendSMS() throws InterruptedException {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("---sendSMS---");
    }
    public synchronized void sendEmail(){
        System.out.println("---sendEmail---");
    }
}
